package org.luxor.commons.workflow.listener;

import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.impl.ActivitiProcessCancelledEventImpl;
import org.luxor.commons.workflow.component.cache.CustomDeploymentCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 流程强制终止
 *
 * @author Mr.Yan  @date: 2021/10/27
 */
public class ProcessCancelledListener implements ActivitiEventHandler {

    private static final Logger log = LoggerFactory.getLogger(ProcessCancelledListener.class);

    private CustomDeploymentCache deploymentCache;

    public ProcessCancelledListener(CustomDeploymentCache deploymentCache) {
        this.deploymentCache = deploymentCache;
    }

    @Override
    public void handle(ActivitiEvent event) {
        // 清除[运行实例流程定义]
        String processDefinitionId = event.getProcessDefinitionId();
        String processInstanceId = event.getProcessInstanceId();
        deploymentCache.removeRuProcessDefinition(processDefinitionId, processInstanceId);

        ActivitiProcessCancelledEventImpl processCancelledEvent = (ActivitiProcessCancelledEventImpl) event;
        log.debug("流程强制终止(ProcessCancelledListener). ProcInstId: " + processCancelledEvent.getProcessInstanceId() +
                ",ExecutionId: " + processCancelledEvent.getExecutionId());
    }

}
